/*
 * bounds_check.h - Lightweight boundary checking functions
 * Following C11 Annex K (Bounds-checking interfaces) standard
 *
 * This header provides safe alternatives to standard C library functions
 * with built-in bounds checking to prevent buffer overflows and other
 * memory safety issues.
 */

#ifndef BOUNDS_CHECK_H
#define BOUNDS_CHECK_H

#include <stddef.h>
#include <stdint.h>

/* Error codes following Annex K specification */
#define BOUNDS_CHECK_SUCCESS 0
#define BOUNDS_CHECK_FAILURE 1
#define BOUNDS_CHECK_INVALID_PARAM 2
#define BOUNDS_CHECK_BUFFER_TOO_SMALL 3

/* String functions */
int strcpy_s(char *dest, size_t dest_size, const char *src);
int strncpy_s(char *dest, size_t dest_size, const char *src, size_t count);
int strcat_s(char *dest, size_t dest_size, const char *src);
int strncat_s(char *dest, size_t dest_size, const char *src, size_t count);

/* Memory functions */
int memcpy_s(void *dest, size_t dest_size, const void *src, size_t count);
int memmove_s(void *dest, size_t dest_size, const void *src, size_t count);
int memset_s(void *dest, size_t dest_size, int value, size_t count);

/* String length with bounds checking */
int strnlen_s(const char *str, size_t str_size, size_t *result);

/* Input/output functions */
int gets_s(char *buffer, size_t buffer_size);

/* Utility functions */
int check_buffer(const void *ptr, size_t size);

#endif /* BOUNDS_CHECK_H */